package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractVersionEntity;
import com.moyuer.bsf.domain.model.Organ;

import javax.persistence.*;
import java.util.Set;

/**
 * 商品标签
 *
 * @author 袁首京<yuanshoujing@gmail.com>
 */
@Entity
public class Tag extends AbstractVersionEntity {

    private static final long serialVersionUID = -7296503011017455518L;

    @Column(length = 30, nullable = false)
    private String name; // 名称

    @Column(length = 30, nullable = false)
    private String spell; // 拼写

    @Column(nullable = false)
    private Long rate = 0l; // 权重

    @JSONField(serialize = false)
    @ManyToOne
    private Organ organ; // 机构

    @Transient
    private String organId;
    @Transient
    private String organName;

    @OneToMany(mappedBy = "tag")
    protected Set<TagGoods> tagGoods; // 商品标签

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSpell() {
        return spell;
    }

    public void setSpell(String spell) {
        this.spell = spell;
    }

    public Long getRate() {
        return rate;
    }

    public void setRate(Long rate) {
        this.rate = rate;
    }

    public Organ getOrgan() {
        return organ;
    }

    public void setOrgan(Organ organ) {
        this.organ = organ;
    }

    public String getOrganId() {
        if (organId != null) {
            return organId;
        }

        if (organ != null) {
            organId = organ.getId();
        }

        return organId;
    }

    public void setOrganId(String organId) {
        this.organId = organId;
    }

    public String getOrganName() {
        if (organName != null) {
            return organName;
        }

        if (organ != null) {
            organName = organ.getName();
        }

        return organName;
    }

    public void setOrganName(String organName) {
        this.organName = organName;
    }

	public Set<TagGoods> getTagGoods() {
		return tagGoods;
	}

	public void setTagGoods(Set<TagGoods> tagGoods) {
		this.tagGoods = tagGoods;
	}
}
